package com.Jano.util;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 用于对ThreadLocal中的请求对象和响应对象进行获取、设置、移除操作
 */
public class RequestContextHolder {
    private static ThreadLocal<HttpServletRequest> curReq = new ThreadLocal<>();
    private static ThreadLocal<HttpServletResponse> curRes = new ThreadLocal<>();

    private RequestContextHolder() {

    }

    public static void setRequest(HttpServletRequest req) {
        curReq.set(req);
    }

    public static HttpServletRequest getRequest() {
        return curReq.get();
    }

    public static void removeRequest() {
        curReq.remove();
    }

    public static void setResponse(HttpServletResponse res) {
        curRes.set(res);
    }

    public static HttpServletResponse getResponse() {
        return curRes.get();
    }

    public static void removeResponse() {
        curRes.remove();
    }

}
